package org.dromara.common.excel.core


/**
 * 默认excel返回对象
 *
 * @author Yjoioooo
 * @author Lion Li
 * @updater LikeYouDo
 * @date 2025/1/9 14:07
 */
open class DefaultExcelResult<T>() : ExcelResult<T> {

    /**
     * 数据对象list
     */
    private var list: MutableList<T> = ArrayList()

    /**
     * 错误信息列表
     */
    private var errorList: MutableList<String?> = ArrayList()

    constructor(list: MutableList<T>, errorList: MutableList<String?>) : this() {
        this.list = list
        this.errorList = errorList
    }

    constructor(excelResult: ExcelResult<T>) : this() {
        this.list = excelResult.getList()
        this.errorList = excelResult.getErrorList()
    }

    override fun getList(): MutableList<T> = list

    override fun getErrorList(): MutableList<String?> = errorList

    /**
     * 获取导入回执
     *
     * @return 导入回执
     */
    override fun getAnalysis(): String {
        val successCount = list.size
        val errorCount = errorList.size
        return if (successCount == 0) {
            "读取失败，未解析到数据"
        } else {
            if (errorCount == 0) {
                "恭喜您，全部读取成功！共${successCount}条"
            } else {
                ""
            }
        }
    }
}
